home *** CD-ROM | disk | FTP | other *** search
/ CU Amiga Super CD-ROM 14 / CU Amiga Magazine's Super CD-ROM 14 (1997)(EMAP Images)(GB)(Track 1 of 3)[!][issue 1997-09].iso / CUCD / Programming / RKMLibsPrgs / graphics_libraries / sprites_bobs / bob.c < prev    next >
C/C++ Source or Header  |  1992-09-03  |  7KB  |  186 lines

  1. /* bob.c
  2. **
  3. ** SAS/C V5.10a
  4. ** lc -b1 -cfist -v -y bob.c
  5. ** blink FROM LIB:c.o bob.o animtools.o LIB LIB:lc.lib LIB:amiga.lib TO bob
  6.  
  7.  
  8. Copyright (c) 1992 Commodore-Amiga, Inc.
  9.  
  10. This example is provided in electronic form by Commodore-Amiga, Inc. for
  11. use with the "Amiga ROM Kernel Reference Manual: Libraries", 3rd Edition,
  12. published by Addison-Wesley (ISBN 0-201-56774-1).
  13.  
  14. The "Amiga ROM Kernel Reference Manual: Libraries" contains additional
  15. information on the correct usage of the techniques and operating system
  16. functions presented in these examples.  The source and executable code
  17. of these examples may only be distributed in free electronic form, via
  18. bulletin board or as part of a fully non-commercial and freely
  19. redistributable diskette.  Both the source and executable code (including
  20. comments) must be included, without modification, in any copy.  This
  21. example may not be published in printed form or distributed with any
  22. commercial product.  However, the programming techniques and support
  23. routines set forth in these examples may be used in the development
  24. of original executable software products for Commodore Amiga computers.
  25.  
  26. All other rights reserved.
  27.  
  28. This example is provided "as-is" and is subject to change; no
  29. warranties are made.  All use is at your own risk. No liability or
  30. responsibility is assumed.
  31. */
  32.  
  33. #include <exec/types.h>
  34. #include <exec/memory.h>
  35. #include <intuition/intuitionbase.h>
  36. #include <graphics/gfx.h>
  37. #include <graphics/gfxbase.h>
  38. #include <graphics/gels.h>
  39. #include <libraries/dos.h>
  40. #include <stdlib.h>
  41. #include "animtools.h"
  42.  
  43. VOID bobDrawGList(struct RastPort *rport, struct ViewPort *vport);
  44. VOID process_window(struct Window *win, struct Bob *myBob);
  45. VOID do_Bob(struct Window *win);
  46.  
  47. struct GfxBase       *GfxBase;       /* pointer to Graphics library */
  48. struct IntuitionBase *IntuitionBase; /* pointer to Intuition library*/
  49. int return_code;
  50. #define GEL_SIZE  4                  /* number of lines in the bob  */
  51.  
  52. /* Bob data - two sets that are alternated between.  Note that this */
  53. /* data is at the resolution of the screen.                         */
  54.  
  55. /* data is 2 planes by 2 words by GEL_SIZE lines                    */
  56. WORD chip bob_data1[2 * 2 * GEL_SIZE] =
  57.         {
  58.         /* plane 1 */
  59.         0xffff, 0x0003, 0xfff0, 0x0003, 0xfff0, 0x0003, 0xffff, 0x0003,
  60.         /* plane 2 */
  61.         0x3fff, 0xfffc, 0x3ff0, 0x0ffc, 0x3ff0, 0x0ffc, 0x3fff, 0xfffc
  62.         };
  63.  
  64. /* data is 2 planes by 2 words by GEL_SIZE lines                     */
  65. WORD chip bob_data2[2 * 2 * GEL_SIZE] =
  66.         {
  67.         /* plane 1 */
  68.         0xc000, 0xffff, 0xc000, 0x0fff, 0xc000, 0x0fff, 0xc000, 0xffff,
  69.         /* plane 2 */
  70.         0x3fff, 0xfffc, 0x3ff0, 0x0ffc, 0x3ff0, 0x0ffc, 0x3fff, 0xfffc
  71.         };
  72.  
  73. NEWBOB myNewBob =                     /* Data for the new bob structure defined in animtools.h */
  74.         {                             /* Initial image, WORD width, line height                */
  75.         bob_data2, 2,  GEL_SIZE,      /* Image depth, plane pick, plane on off, VSprite flags  */
  76.         2, 3, 0, SAVEBACK | OVERLAY,  /* dbuf (0=false), raster depth, x,y position, hit mask, */
  77.         0, 8, 160, 100,  0,0,         /* me mask                                               */
  78.         };
  79.  
  80. struct NewWindow myNewWindow =
  81.         {                             /* information for the new window */
  82.         80, 20, 400, 150, -1, -1, CLOSEWINDOW | INTUITICKS,
  83.         ACTIVATE | WINDOWCLOSE | WINDOWDEPTH | RMBTRAP,
  84.         NULL, NULL, "Bob", NULL, NULL, 0, 0, 0, 0, WBENCHSCREEN
  85.         };
  86.  
  87. /* Draw the Bobs into the RastPort. */
  88. VOID bobDrawGList(struct RastPort *rport, struct ViewPort *vport)
  89. {
  90. SortGList(rport);
  91. DrawGList(rport, vport);
  92. /* If the GelsList includes true VSprites, MrgCop() and LoadView() here */
  93. WaitTOF() ;
  94. }
  95.  
  96. /* Process window and dynamically change bob: Get messages. Go away on CLOSEWINDOW.
  97. ** Update and redisplay bob on INTUITICKS. Wait for more messages.
  98. */
  99. VOID process_window(struct Window *win, struct Bob *myBob)
  100. {
  101. struct IntuiMessage *msg;
  102.  
  103. FOREVER {
  104.         Wait(1L << win->UserPort->mp_SigBit);
  105.         while (NULL != (msg = (struct IntuiMessage *)GetMsg(win->UserPort)))
  106.                 {
  107.                 /* only CLOSEWINDOW and INTUITICKS are active */
  108.                 if (msg->Class == CLOSEWINDOW)
  109.                         {
  110.                         ReplyMsg((struct Message *)msg);
  111.                         return;
  112.                         }
  113.                 /* Must be INTUITICKS:  change x and y values on the fly.  Note:
  114.                 ** do not have to add window offset, Bob is relative to the
  115.                 ** window (sprite relative to screen).
  116.                 */
  117.                 myBob->BobVSprite->X = msg->MouseX + 20;
  118.                 myBob->BobVSprite->Y = msg->MouseY + 1;
  119.                 ReplyMsg((struct Message *)msg);
  120.                 }
  121.         /* after getting a message, change image data on the fly */
  122.         myBob->BobVSprite->ImageData =
  123.                 (myBob->BobVSprite->ImageData == bob_data1) ? bob_data2 : bob_data1;
  124.         InitMasks(myBob->BobVSprite); /* set up masks for new image */
  125.         bobDrawGList(win->RPort, ViewPortAddress(win));
  126.         }
  127. }
  128.  
  129.  
  130. /* Working with the Bob: setup the GEL system, and get a new Bob (makeBob()).
  131. ** Add the bob to the system and display. Use the Bob.  When done, remove
  132. ** the Bob and update the display without the bob. Cleanup everything.
  133. */
  134. VOID do_Bob(struct Window *win)
  135. {
  136. struct Bob         *myBob;
  137. struct GelsInfo    *my_ginfo;
  138.  
  139. if (NULL == (my_ginfo = setupGelSys(win->RPort, 0x03)))
  140.         return_code = RETURN_WARN;
  141. else
  142.         {
  143.         if (NULL == (myBob = makeBob(&myNewBob)))
  144.                 return_code = RETURN_WARN;
  145.         else
  146.                 {
  147.                 AddBob(myBob, win->RPort);
  148.                 bobDrawGList(win->RPort, ViewPortAddress(win));
  149.                 process_window(win, myBob);
  150.                 RemBob(myBob);
  151.                 bobDrawGList(win->RPort, ViewPortAddress(win));
  152.                 freeBob(myBob, myNewBob.nb_RasDepth);
  153.                 }
  154.         cleanupGelSys(my_ginfo,win->RPort);
  155.         }
  156. }
  157.  
  158.  
  159. /* Example bob program: First open up the libraries and a window. */
  160. VOID main(int argc, char **argv)
  161. {
  162. struct Window      *win;
  163.  
  164. return_code = RETURN_OK;
  165.  
  166. if (NULL == (GfxBase = (struct GfxBase *)OpenLibrary(GRAPHICSNAME,37L)))
  167.         return_code = RETURN_FAIL;
  168. else
  169.         {
  170.         if (NULL == (IntuitionBase = (struct IntuitionBase *)OpenLibrary(INTUITIONNAME,37L)))
  171.                 return_code = RETURN_FAIL;
  172.         else
  173.                 {
  174.                 if (NULL == (win = OpenWindow(&myNewWindow)))
  175.                         return_code = RETURN_FAIL;
  176.                 else
  177.                         {
  178.                         do_Bob(win);
  179.                         CloseWindow(win);
  180.                         }
  181.                 CloseLibrary((struct Library *)IntuitionBase);
  182.                 }
  183.         CloseLibrary((struct Library *)GfxBase);
  184.         }
  185. exit(return_code);
  186. }